
ChatBotSettings = { }
ChatBotSettings.Name = ".:CG:. Nick"
ChatBotSettings.Color = Color( 0 , 0 , 255 , 255 )
ChatBotSettings.Inter = " : "
ChatBotSettings.Delay = 0.5
ChatBotSettings.EasterEgg = "CupCakes are fun to eat"
ChatBotSettings.EasterEggAnswer = "OMG !!! You just found my favorite phrase! Congrats!"
ChatBotSettings.WierdDelay = 90
ChatBotSettings.File = "ChatBot.txt"
ChatBotSettings.FileG = "ChatBot_G.txt"
ChatBotSettings.FileAG = "ChatBot_AG.txt"

ChatBotSettings.Adverts = { }
ChatBotSettings.Adverts.Color = Color( 100,100,100 )
ChatBotSettings.Adverts.Delay = 30

AddCSLuaFile("autorun/client/cl_vgui.lua")
AddCSLuaFile("autorun/client/cl_functions.lua")
AddCSLuaFile("autorun/SH_PluginsUI.lua")

ChatBot = { }


if CLIENT then
	usermessage.Hook("ChatBot.Call", function( um )
		local _Message = um:ReadString()
		if _Message then
			timer.Simple( ChatBotSettings.Delay , function()
				chat.AddText(
					ChatBotSettings.Color , ChatBotSettings.Name ,
					Color(255,255,255), ChatBotSettings.Inter,
					Color(255,255,255), _Message)
				chat.PlaySound()
			end)
		end
	end)
		
	usermessage.Hook("ChatBot.Call.Advert", function( um )
		local _Message = um:ReadString()
		if _Message then
			timer.Simple( ChatBotSettings.Delay , function()
				chat.AddText(
					ChatBotSettings.Adverts.Color, "(ADVERT) ",
					ChatBotSettings.Color , ChatBotSettings.Name ,
					Color(255,255,255), ChatBotSettings.Inter,
					Color(255,255,255), _Message)
				chat.PlaySound()
			end)
		end
	end)
	
	usermessage.Hook("ChatBot.Call.UTIME", function( um )
		local _Message = um:ReadString()
		if _Message then
			timer.Simple( ChatBotSettings.Delay , function()
				chat.AddText(
					Color(20,255,20), "( UTIME ) ",
					ChatBotSettings.Color , ChatBotSettings.Name ,
					Color(255,255,255), ChatBotSettings.Inter,
					Color(255,255,255), _Message)
				chat.PlaySound()
			end)
		end
	end)
end

if SERVER then

	local _ChatPrefix = "$";
	
	if not _ChatCommands then
		_ChatCommands = { }
	end

	local function ChatBotAddCommand( txt, func )
		_ChatCommands[ _ChatPrefix .. txt ] = func;
	end

	hook.Add( "PlayerSay", "ChatBot.Command.Caller", function( ply, text, toall )

		local tab = string.Explode( " ", text );
		local func = _ChatCommands[ tab[1] ];
			
		if ( func ) then

			local c = tab[1];
			table.remove( tab, 1 )
			
			func( ply, c, tab  );
		
			return "";
		
			
		end

	end );

	
	ChatBot.Plugins = { }

	local list1 = file.FindInLua( "Plugins/*.lua")
	Msg("\n\n------ Loading Plugins For Nick ------\n\n\n")
	function ChatBot.ReloadPlugins()
		for _, file1 in pairs(list1) do
			include( "Plugins/" .. file1 )
			Msg("Loading " .. Plugin.Name .. " plugin\n" )
			Plugin.First()
			Plugin.Second()
			ChatBot.Plugins[Plugin.Name] = { }
			ChatBot.Plugins[Plugin.Name]["Name"] = Plugin.Name
			ChatBot.Plugins[Plugin.Name]["Info"] = Plugin.Info
			ChatBot.Plugins[Plugin.Name]["Usage"] = Plugin.Usage
			ChatBot.Plugins[Plugin.Name]["First"] = Plugin.First
			ChatBot.Plugins[Plugin.Name]["Second"] = Plugin.Second
			if Plugin.ChatCommand then
				ChatBot.Plugins[Plugin.Name]["OnChat"] = Plugin.OnChat
				ChatBot.Plugins[Plugin.Name]["ChatCommand"] = Plugin.ChatCommand
				ChatBotAddCommand( Plugin.ChatCommand , Plugin.OnChat )
			end
			if Plugin.Category then
				ChatBot.Plugins[Plugin.Name]["Category"] = Plugin.Category
			else
				ChatBot.Plugins[Plugin.Name]["Category"] = "Other"
			end
		end
	end
	ChatBot.ReloadPlugins()
	Msg("\n\n------  Loaded Plugins For Nick ------\n\n\n")
	
	concommand.Add("ChatBot_ReloadPlugins", function( ply )
		if ply:IsAdmin() then
			ChatBot.ReloadPlugins()
		end
	end)
end
